/* indent size: 1 */

module.exports = app => {
	const DataTypes = app.Sequelize;

	const Model = app.model.define('attr_key', {
		id: {
			type: DataTypes.INTEGER(8).UNSIGNED,
			allowNull: false,
			primaryKey: true,
			autoIncrement: true
		},
		goods_type_id: {
            type: DataTypes.INTEGER(11),
            allowNull: true,
            defaultValue: null,
            comment: '商品类型'
		},
		name: {
			type: DataTypes.STRING(255),
			allowNull: false,
			defaultValue: ''
		},
		is_delete: {
			type: DataTypes.INTEGER(1).UNSIGNED,
			allowNull: false,
			defaultValue: '0',
			comment: '是否删除，0->存在，1->删除'
		},
        shop_id: {
            type: DataTypes.INTEGER(11),
            allowNull: true,
            defaultValue: null,
            comment: '商家ID，预留SASS功能'
        },
	}, {
		tableName: 'attr_key',
		timestamps: false
	});

	Model.sync({ alter: true });
	
	Model.associate = function() {
		app.model.AttrKey.hasMany(app.model.AttrVal, {
            foreignKey: 'attr_key_id',
            constraints: false,
			sourceKey: 'id'
		});
		app.model.AttrKey.hasOne(app.model.GoodsType, {
            foreignKey: 'id',
            constraints: false,
			sourceKey: 'goods_type_id'
		});

	}

	return Model;
};
